package cn.ekuma.epos.datalogic.define.dao.erp.ordercalc;


import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.util.JsonUtil;
import com.openbravo.bean.erp.ordercalc.OrderTypeCalcConfig;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.ImageUtils;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class OrderTypeCalcConfigDAO extends ModifiedLogDAO<OrderTypeCalcConfig>{


	public OrderTypeCalcConfigDAO(I_Session s) {
		super(s);
	}

	@Override
    public TableDefinition getTable() {
        return new TableDefinition(s,
                  "ORDERTYPECALCCONFIG",
                  new Field[]{
                       new Field("ID",Datas.STRING,Formats.STRING),
                       new Field("ORDERTYPEID",Datas.STRING,Formats.STRING),
                       new Field("ORDERCALCID",Datas.STRING,Formats.STRING),
                       new Field("ABLE",Datas.BOOLEAN,Formats.BOOLEAN),
                       new Field("ARRT",Datas.STRING,Formats.STRING),
                       new Field("LASTMODIFIED",Datas.TIMESTAMP, Formats.TIMESTAMP)
                  },new int[]{0});
    }

	@Override
	public void writeInsertValues(DataWrite dp, OrderTypeCalcConfig obj)
			throws BasicException {
		dp.setString(1,obj.getKey());
		dp.setString(2,obj.getOrderTypeId());
		dp.setString(3,obj.getOrderCalcId());
		dp.setBoolean(4,obj.isAbled());
		dp.setString(5, JsonUtil.toString(obj.getProperties()));
		dp.setTimestamp(6,obj.getLastModified());
		
	}

	@Override
	public Class getSuportClass() {
		return OrderTypeCalcConfig.class;
	}

	@Override
	public OrderTypeCalcConfig readValues(DataRead dr, OrderTypeCalcConfig obj)
			throws BasicException {
		if(obj==null)
			obj=new OrderTypeCalcConfig();
		obj.setKey(dr.getString(1));
		obj.setOrderTypeId(dr.getString(2));
		obj.setOrderCalcId(dr.getString(3));
		obj.setAbled(dr.getBoolean(4));
		obj.setProperties(JsonUtil.getHashMap(dr.getString(5)));
		obj.setLastModified(dr.getTimestamp(6));
		return obj;
	}
}
